package com.bona.service.common;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

@Service("genericService")
public class GenericService {

	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	public Map<String, Object> queryForMap(String sql) throws DataAccessException {
		return jdbcTemplate.queryForMap(sql);
	}
	
	public Map<String, Object> queryForMap(String sql, Object[] args) throws DataAccessException {
		return jdbcTemplate.queryForMap(sql, args);
	}
	
	public int queryForInt(String sql) throws DataAccessException {
		return jdbcTemplate.queryForInt(sql);
	}
	
	public int queryForInt(String sql, Object[] args) throws DataAccessException {
		return jdbcTemplate.queryForInt(sql, args);
	}
	
	public <T> T queryForObject(String sql, Class<T> requiredType) throws DataAccessException {
		return jdbcTemplate.queryForObject(sql, requiredType);
	}
	
	public <T> T queryForObject(String sql, Object[] args, Class<T> requiredType) throws DataAccessException {
		return jdbcTemplate.queryForObject(sql, args, requiredType);
	}
	
	public List<Map<String, Object>> queryForList(String sql) throws DataAccessException {
		return jdbcTemplate.queryForList(sql);
	}
	
	public <T> List<T> queryForList(String sql, Class<T> elementType) throws DataAccessException {
		return jdbcTemplate.queryForList(sql, elementType);
	}
	
	public <T> List<T> queryForList(String sql, Object[] args, Class<T> elementType) throws DataAccessException {
		return jdbcTemplate.queryForList(sql, args, elementType);
	}
	
	public List<Map<String, Object>> queryForList(String sql, Object[] args) throws DataAccessException {
		return jdbcTemplate.queryForList(sql, args);
	}
	
	public int update(String sql) throws DataAccessException {
		return jdbcTemplate.update(sql);
	}
	
	public int update(String sql, Object[] args) throws DataAccessException {
		return jdbcTemplate.update(sql, args);
	}
	 
	public int[] batchUpdate(String[] sql) throws DataAccessException {
		return jdbcTemplate.batchUpdate(sql);
	}
	
	public int[] batchUpdate(String sql, List<Object[]> batchArgs) {
		return jdbcTemplate.batchUpdate(sql, batchArgs);
	}
	
	public int delete(String sql) throws DataAccessException {
		return jdbcTemplate.update(sql);
	}
	
	public int delete(String sql, Object[] args) throws DataAccessException {
		return jdbcTemplate.update(sql, args);
	}
}
